package com.uit.smarttool.ultility;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.uit.smarttool.activity.R;

public class LazyAdapter extends BaseAdapter {
    
    private Activity activity;
    private String[] image;
    private String[] label;
    private String[] price;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 
    
    public LazyAdapter(Activity activity, String[] image, String[] label, String[] price) {
        this.activity = activity;
        this.image = image;
        this.label = label;
        this.price = price;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return image.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.item, null);

        TextView text=(TextView)vi.findViewById(R.id.text);
        TextView textDG=(TextView)vi.findViewById(R.id.text_dg);
        ImageView imageView=(ImageView)vi.findViewById(R.id.image);
        text.setText(label[position]);
        textDG.setText(price[position]);
        imageLoader.DisplayImage(image[position], imageView);
        return vi;
    }
}